<html>
<?php
    require_once("menu.php");
	require_once('controllers/forum.php');
	require_once('controllers/user.php');
	require_once('model/db_driver.php');
	
	$user = User::getCurrentUser();
	if(isset($_POST['txtCommento'])){
		if($user == null){
			echo "<script type='text/javascript'>alert('Attenzione: sessione scaduta. Autenticarsi nuovamente');</script>";
		}else{
			$forum = new Forum();
			$forum->addComment($user->getId(), $_POST['txtCommento']);
			$driver = new DbDriver();
			$driver->addNews("Nuovo commento in bacheca", $user->getAlias() . " ha aggiunto un commento in bacheca");
		}
	}
?>
	<head>
		<title>Fantacalcio - Bacheca</title>
		<link rel="stylesheet" href="fantacalcio.css" type="text/css"/>		<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
		<script type="text/javascript" src="tinymce/jscripts/tiny_mce/tiny_mce.js" > </script> 
		<script type="text/javascript"> 
tinyMCE.init({
        // General options
        mode : "textareas",
        theme : "advanced",
        plugins : "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : true,

        // Skin options
        skin : "o2k7",
        skin_variant : "silver",

        // Example content CSS (should be your site CSS)
        content_css : "css/example.css",
        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "js/template_list.js",
        external_link_list_url : "js/link_list.js",
        external_image_list_url : "js/image_list.js",
        media_external_list_url : "js/media_list.js",
        // Replace values for the template plugin
        template_replace_values : {
                username : "Some User",
                staffid : "991234"
        }
});

</script>
	</head>
	<body>
		<table class="pageTable" cellpadding='0' cellspacing='0'>
			<tr>
				<td>
					<?php echo printMasterMenu('Bacheca');?>
				</td>
			</tr>
			<tr>
				<td class='contentPage'>
					<table style="width:100%">
						<tr>
							<td class="pageTitle">Bacheca</td>
						</tr>
						<tr>
							<td>
								<div style='width:980px;height:600px;overflow:scroll;
									border-color:gray;border-style:solid;border-width:1px;
									margin-left:20px;'>
									<table style='width:100%;'>
										<tr>
										<?php 
											$bacheca = new Forum();
											for($i=0; $i < $bacheca->getNumMessages(); $i++){
												$m = $bacheca->getMessage($i);
												echo "<tr><td class='messageItem'>";
												echo "<span style='color:red'>il "; 
												echo $m->getDate() . "</span> "; 
												echo "<span style='font-weight:bold;color:blue;'>";
												echo $m->getUser() . "</span>";
												echo "<span > ha scritto:</span> <br /><span style='font-size:12px'>";
												echo $m->getText();
												echo '</span></td></tr>';
											}
										?>
										</tr>
									</table>
								</div>
							</td>
						</tr>
						<tr>
							<td style='padding-left:20px;width:100%;'>
								<br />
								<br />
								<?php									$user=User::getCurrentUser();
									if($user != null){
										echo "<form method='POST' action='bacheca.php'>";
										echo "Inserisci un commento:<br />";
										echo "<textarea name='txtCommento' style='width:95%;' ></textarea><br />";
										echo "<input type='submit' name='InsertComment' value='Inserisci commento' />";
										echo "</form>";
									}
								?>
							</td>
						</tr>
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<?php printFooter() ?>
				</td>
			</tr>
		</table>
	</body>
</html>